//
// Created by zhulingfeng on 2020/2/8.
//
#include <gtest/gtest.h>
#include <vector>
#include "binary_tree/binary_tree_traversal.hpp"
#include "binary_tree/create_binary_tree.hpp"
#include "create_binary_tree_test.hpp"

class BinaryTreeTraversalTest : public CreateBinaryTreeTest {};

TEST_F(BinaryTreeTraversalTest, PreOrderIterative) {  // NOLINT(cert-err58-cpp)
  std::vector<int> output;
  for (int i = 0; i < level_order_strings_.size(); ++i) {
    output.clear();
    auto root = CreateBTFromLevelOrder(level_order_strings_[i]);
    BinaryTreeTraversalIterative(root, BinaryTreeTraversalOrder::pre, output);
    EXPECT_EQ(pre_order_gts_[i], output);
  }
}

TEST_F(BinaryTreeTraversalTest, InOrderIterative) {
  std::vector<int> output;
  for (int i = 0; i < level_order_strings_.size(); ++i) {
    output.clear();
    auto root = CreateBTFromLevelOrder(level_order_strings_[i]);
    BinaryTreeTraversalIterative(root, BinaryTreeTraversalOrder::in, output);
    EXPECT_EQ(in_order_gts_[i], output);
  }
}

TEST_F(BinaryTreeTraversalTest, PostOrderIterative) {
  std::vector<int> output;
  for (int i = 0; i < level_order_strings_.size(); ++i) {
    output.clear();
    auto root = CreateBTFromLevelOrder(level_order_strings_[i]);
    BinaryTreeTraversalIterative(root, BinaryTreeTraversalOrder::post, output);
    EXPECT_EQ(post_order_gts_[i], output);
  }
}

TEST_F(BinaryTreeTraversalTest, LevelOrderIterative) {
  std::vector<int> output;
  for (int i = 0; i < level_order_strings_.size(); ++i) {
    output.clear();
    auto root = CreateBTFromLevelOrder(level_order_strings_[i]);
    LevelOrderTraversalIterative(root, output);
    EXPECT_EQ(level_order_gts_[i], output);
  }
}
